<?php

	class EditCategorieCommand implements ICommand
	{
		public function execute($event)
		{
			$name 		= $event->data['name'];
			$urlname 	= EbUrlRoutingToolkit::formatToUrl($name);
			$model 		= EbModel::getModel('VarPeople','Categorie');
			$buffer 	= $model->selectByName($name);
			$id			= EbController::$request->id;

			if (is_null($id) || $id == 0)
			{
				if (count($buffer) > 0)
				{
					return new Event('redirect','/admin-categorie?id=0');
				}
				else
				{		
					$model->insert((object) array('name' => $name,'urlname' => $urlname));
				}	
			}
			else
			{
				$model->update((object) array('ca_id' => $id,'name' => $name,'urlname' => $urlname));
			}		
			
			return new Event('redirect','/admin-categorie');
		}		
	}